package indi.zhifa.recipe.bailan.busy.auth.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import indi.zhifa.recipe.bailan.busy.auth.entity.po.DeptEntity;
import indi.zhifa.recipe.bailan.busy.auth.dao.mapper.DeptMapper;
import indi.zhifa.recipe.bailan.busy.auth.dao.service.IDeptDbService;
import indi.zhifa.recipe.bailan.busy.auth.entity.po.DeviceGroupEntity;
import indi.zhifa.recipe.bailan.framework.mysql.entity.annotations.ZfDbService;
import indi.zhifa.recipe.bailan.framework.mysql.service.impl.ZfDbServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户的部门表，用于用户管理 服务实现类
 * </p>
 *
 * @author 织法
 * @since 2023-01-09
 */
@ZfDbService(name = "DeptEntity")
public class DeptDbServiceImpl extends ZfDbServiceImpl<DeptMapper, DeptEntity> implements IDeptDbService {
    @CacheEvict(key = "#pAuthId")
    @Override
    public DeptEntity deleteByAuthId(Long pAuthId) {
        LambdaQueryWrapper<DeptEntity> queryWrapper = Wrappers.<DeptEntity>lambdaQuery()
                .eq(DeptEntity::getAuthId,pAuthId);
        DeptEntity entity = findOne(queryWrapper);
        if(null != entity){
            removeById(entity.getId());
        }
        return entity;
    }

    @Cacheable(key = "#pAuthId",condition = "null != #result")
    @Override
    public DeptEntity findByAuthId(Long pAuthId){
        LambdaQueryWrapper<DeptEntity> queryWrapper = Wrappers.<DeptEntity>lambdaQuery()
                .eq(DeptEntity::getAuthId,pAuthId);
        DeptEntity entity = findOne(queryWrapper);
        return entity;
    }
}
